import { useAdminStore } from "@/store/admin";
import { App } from "vue";

export const setupDirectives = (app: App<Element>) => {
    app.directive('hasPerm', {
        mounted(el, binding, vnode) {
            // 判断 binding.value 在不在权限数组中
            const adminStore = useAdminStore();
            const hasPerm = findPermission(adminStore.menusData, binding.value);
            if (!hasPerm) {
                el.remove();
            }
        },
    })
}
const findPermission = (menusData: menuItem[], value: string) => {
    
    for (let item of menusData) {
        if (item.children) {
            const has = findPermission(item.children, value);
            if (has) {
                return true;
            }
        }

        if (item.path == value) {
        console.log(value);
            return true;
        }
    
    }
}